﻿using OCR.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OCR.SystemThread
{
    class TestSetInfoThread
    {
        public static bool TestSetInfoThread_Flowrec = false;
        public static Thread TestSetInfoFlow_Thread = null;

        public static int iTestSetInfo_Step = 0;

        public static bool TestSetInfoThread_Pause = false;

        public static DateTime startDt;
        public static void TestSetInfo_Thread()
        {
            iTestSetInfo_Step = 1;
            TestSetInfoThread_Pause = false;
            TestSetInfoThread_Flowrec = true;
            TestSetInfoFlow_Thread = new Thread(TestSetInfoThreadFlow);
            TestSetInfoFlow_Thread.IsBackground = true;
            TestSetInfoFlow_Thread.Start();
        }

        private static void TestSetInfoThreadFlow()
        {
            while (TestSetInfoThread_Flowrec)
            {
                if (!TestSetInfoThread_Pause)
                {
                    switch (iTestSetInfo_Step)
                    {
                        case 0:
                            Thread.Sleep(1000);
                            iTestSetInfo_Step = 5;
                            break;
                        case 5:
                            OCR_Form.TestSaveImg();
                            iTestSetInfo_Step = 0;
                            break;
                        case 10:
                            startDt = DateTime.Now;
                            //Thread.Sleep(300);
                            iTestSetInfo_Step = 11;
                            break;
                        case 11:
                            //Console.WriteLine((DateTime.Now - startDt).TotalMilliseconds);
                            //AlgorithmModule_GPU.ImageHandleV2_Refresh_ByteArray("TemplateInput\\TestRefresh.bmp");
                            if((DateTime.Now - startDt).TotalMilliseconds >= 310)
                            {
                                Console.WriteLine("延迟310"); 
                                iTestSetInfo_Step = 15;
                            }
                            //Thread.Sleep(300);

                            break;
                        case 15:
                            //AlgorithmModule_GPU.ImageHandleV2_Refresh_ByteArray("TemplateInput\\TestRefresh.bmp");
                            OCR_Form.TestSaveImg_IO2();
                            iTestSetInfo_Step = 10;
                            break;
                    }
                }


            }

        }
    }
}
